package com.chen.springboot.controller;

import com.chen.springboot.common.AuthAccess;
import com.chen.springboot.common.Result;
import com.chen.springboot.entity.ItemOption;
import com.chen.springboot.service.ItemOptionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 商品选项接口
 */
@Api(tags = {"商品选项接口"})
@RestController
@RequestMapping("/itemOption")
public class ItemOptionController {

    @Autowired
    private ItemOptionService itemOptionService;

    @AuthAccess
    @ApiOperation("根据商品ID获取商品选项信息")
    @GetMapping("/getByItemId")
    public Result<?> getByItemId(@RequestParam Long itemId) {
        ItemOption itemOption = itemOptionService.getByItemId(itemId);
        return Result.success(itemOption);
    }

    @ApiOperation("新增商品选项")
    @PostMapping
    public Result<?> save(@RequestBody ItemOption itemOption) {
        itemOptionService.save(itemOption);
        return Result.success();
    }

    @ApiOperation("更新商品选项信息")
    @PutMapping
    public Result<?> update(@RequestBody ItemOption itemOption) {
        itemOptionService.updateById(itemOption);
        return Result.success();
    }

    @ApiOperation("删除商品选项信息")
    @DeleteMapping
    public Result<?> delete(@RequestParam Long id) {
        itemOptionService.removeById(id);
        return Result.success();
    }
}

